package com.frank.big.formatter;

import org.springframework.format.Formatter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * @author 小石潭记
 * @date 2020/10/23 10:51
 * @Description: ${todo}
 */
@Component
public class ZoneDateTimeFormatter implements Formatter<ZonedDateTime> {

    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;

    @Override
    public ZonedDateTime parse(String s, Locale locale) throws ParseException {
        return ZonedDateTime.parse(s, dateTimeFormatter);
    }

    @Override
    public String print(ZonedDateTime zonedDateTime, Locale locale) {
        return dateTimeFormatter.format(zonedDateTime);
    }
}
